package cn.tedu.entity;


import cn.tedu.util.XmlUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;

import java.util.Map;

/**
 * 普通文本消息
 * @author Kiven
 */
@Data
@XStreamAlias("xml")
public class TextMsg extends BaseMsg {
    @XStreamAlias("Content")
    private String content;

    @XStreamAlias("MsgId")
    private String msgId;

    public static TextMsg of(Map<String, Object> objectMap, String content)
    {
        TextMsg textMessage = new TextMsg();
        textMessage.init(objectMap);
        textMessage.setContent(content);
        return textMessage;
    }
    public static TextMsg ofSendMsg(Map<String, Object> objectMap, String
            content) {
        TextMsg textMessage = new TextMsg();
        textMessage.init(objectMap);
        textMessage.setContent(content);
        textMessage.setMsgType("text");

        String from = textMessage.getFromUserName();
        textMessage.setFromUserName(textMessage.getToUserName());
        textMessage.setToUserName(from);

        return textMessage;
    }
    public String toXml() {
        return XmlUtils.beanToXml(this, TextMsg.class);

    }
}
